const axios = require('axios');

function addressToLocation(req) {
    return new Promise((resolve, reject) => {
        // 准备请求参数
        const { address, key } = req;
        // 构造请求URL
        const keyword = `https://apis.map.qq.com/ws/place/v1/suggestion/?region=保定&keyword=${encodeURIComponent(address)}&key=${key}`
        // 发起 GET 请求
        axios.get(keyword)
            .then(response => {
                resolve(response.data); // 将结果传递给调用者
            })
            .catch(error => {
                console.error('Error fetching data from Tencent Map API:', error);
                reject(error); // 将错误传递给调用者
            });
    });
}

module.exports = addressToLocation;

